package com.purong.purong.util;

import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

/**
 * Created by zengwenjie on 2017/12/14.
 */
public class ZeroStartUnableTextWatch implements TextWatcher {
    private EditText ed;
    public ZeroStartUnableTextWatch(EditText ed){
        this.ed=ed;
    }
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        if (s.toString().startsWith("0")&&s.length()>1){
            ed.setText(s.toString().replaceFirst("0",""));
            ed.setSelection(ed.getText().toString().trim().length());
        }
    }

    @Override
    public void afterTextChanged(Editable s) {

    }
}
